/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode deleteNode(ListNode head, int val) {
        ListNode node = new ListNode(0);
        node.next = head;
        head = node;
        while(node != null && node.next != null){
            if(node.next.val == val){
                ListNode temp = node.next;
                node.next = temp.next;
                temp.next = null;
                return head.next;
            }
            node = node.next;
        }
        return null;
    }
}